﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Presentation
{
    [DefaultEvent("LClick")]
    public partial class UserControlBBCode : UserControl
    {
        public UserControlBBCode()
        {
            InitializeComponent();
            _Tilte = "Tilte";
            _ColorNormal = this.BackColor;
            _ColorEnter = Color.FromArgb(200, 193, 210, 238);
            _ColorClick = Color.FromArgb(200, 152, 181, 226);
        }

        #region

        protected Bitmap _picIcon;
        [Browsable(true)]
        public Bitmap PicIcon
        {
            get { return _picIcon; }
            set { _picIcon = value; }
        }

        protected string _Tilte;
        public string Tilte
        {
            get { return _Tilte; }
            set
            {
                _Tilte = value;
                Invalidate();
            }
        }

        protected string _Detail;
        public string Detail
        {
            get { return _Detail; }
            set { _Detail = value; }
        }

        protected Color _ColorNormal;
        public Color ColorNormal
        {
            get { return _ColorNormal; }
            set
            {
                _ColorNormal = value;
                this.BackColor = _ColorNormal;
            }
        }

        protected Color _ColorEnter;
        public Color ColorEnter
        {
            get { return _ColorEnter; }
            set { _ColorEnter = value; }
        }

        protected Color _ColorClick;
        public Color ColorClick
        {
            get { return _ColorClick; }
            set { _ColorClick = value; }
        }

        public event MouseEventHandler LClick;

        #endregion

        private void UserControlBBCode_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            if (PicIcon != null)
            {
                int width = PicIcon.Width;
                int height = PicIcon.Height;
                //if (height != Width)
                //{
                //    Double _temp = (Double)(PicIcon.Height / Width);
                //    width = (int)(PicIcon.Width / _temp);
                //    height = (int)(PicIcon.Height / _temp);
                //}
                this.Size = new Size(width, height);
                g.DrawImage(PicIcon, 0, 0, width, height);
            }
            else
            {
                g.DrawString(Tilte, Font, new SolidBrush(Color.Black), new Point(0,(Height-(int)Font.Size)/4));
            }
            if (_MouseEnter == true)
            {
                g.DrawRectangle(new Pen(Color.Black), new Rectangle(new Point(0, 0), new Size(Width-1, Height-1)));
            }
        }

        private Boolean _MouseEnter = false;
        private void UserControlBBCode_MouseEnter(object sender, EventArgs e)
        {
            _MouseEnter = true;
            this.BackColor = _ColorEnter;
            Invalidate();
        }

        private void UserControlBBCode_MouseHover(object sender, EventArgs e)
        {
            if (Detail != null)
                ttDetail.Show(Detail, this);
        }

        private void UserControlBBCode_MouseLeave(object sender, EventArgs e)
        {
            _MouseEnter = false;
            this.BackColor = _ColorNormal;
            Invalidate();
        }

        private void UserControlBBCode_MouseDown(object sender, MouseEventArgs e)
        {
            this.BackColor = _ColorClick;
        }

        private void UserControlBBCode_MouseUp(object sender, MouseEventArgs e)
        {
            if (_MouseEnter)
                this.BackColor = _ColorEnter;
            else
                this.BackColor = _ColorNormal;
        }

        private void UserControlBBCode_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                LClick(sender, e);
            }
        }

    }
}
